package com.coocaa.ops.plus.dashboard.v1.plugin;

import com.coocaa.ops.common.core.security.util.SecurityUtil;
import com.coocaa.ops.plus.core.base.annotation.MyAuth;
import com.coocaa.ops.plus.core.base.enums.MyRoleEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.TreeMap;

/**
 * @author tangminghong
 * @date 2020-09-16
 */
@Controller
@RequestMapping("/myExtend/internalPluginConf")
public class PluginConfController {

    @RequestMapping("/getDetailInfo")
    public Object getDetailInfo(@RequestParam("id") Integer id, HttpServletRequest request) {
        /*String jsonStr = "{\"pluginInfo\":{\"id\":"+id+"}}";
        request.setAttribute("jsonStr", jsonStr);
        String sign = SecurityUtil.sign(null, getParamsMap(jsonStr));
        request.setAttribute("sign", sign);*/
        request.setAttribute("id", id);
        return "forward:/myExtend/v1/plugin/internal/getDetailInfo";
    }

    @MyAuth(validAuth = true, hasRoles = {MyRoleEnums.ROLE_ADMIN})
    @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
    public Object addOrUpdate(@RequestParam("jsonStr") String jsonStr ,HttpServletRequest request) {
        request.setAttribute("jsonStr", jsonStr);
        //String sign = SecurityUtil.sign(null, getParamsMap(jsonStr));
        //request.setAttribute("sign", sign);
        return "forward:/myExtend/v1/plugin/internal/addOrUpdate";
    }


    private TreeMap<String, String> getParamsMap(String jsonStr) {
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("jsonStr",jsonStr.toString());
        return treeMap;
    }
}
